
/**
 * 模板列表数据的格式转换
 * 原数据格式
 [{
    roleType,
    roleTypeName,
    roles: [
        {
            code,
            nameZh,
            nameEn,
            showStatus
        }
    ]
 }]
 * 要转换成
 [{
    id,
    pId
    isLeaf,
    title
    ...otherField
 }]
 * @param data
 */
export const parseRoleDataToTree = data => {
    const result = [];
    if (data?.length) {
        data.forEach(item => {
            result.push({
                id: item.roleType,
                value: item.roleType,
                isLeaf: false,
                pId: null,
                title: item.roleTypeName,
                ...item
            });
            if (item.roles?.length) {
                item.roles.forEach(role => {
                    result.push({
                        id: role.code,
                        value: role.code,
                        isLeaf: true,
                        pId: item.roleType,
                        title: role.nameZh,
                        ...role
                    });
                });
            }
        });
    }
    return result;
};
